﻿namespace ufida.u9.ait.openapi
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using ufida.u9.ait.openapi.utils;
    using UFIDA.U9.PM.DTOs;
    using UFIDA.U9.PM.Enums;
    using UFIDA.U9.PM.PM_Util;
    using UFIDA.U9.PM.PO;
    using UFSoft.UBF.AopFrame;

    /// <summary>
    /// POApproveSV partial 
    /// </summary>	
    public partial class POApproveSV 
	{	
		internal BaseStrategy Select()
		{
			return new POApproveSVImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class POApproveSVImpementStrategy : BaseStrategy
	{
		public POApproveSVImpementStrategy() { }

		public override object Do(object obj)
		{						
			POApproveSV bpObj = (POApproveSV)obj;

			return CodeUtils.DocUpdateNT<DocDTOData, PurchaseOrder>(bpObj, bpObj.Data,
				(doc) =>
				{
                    if (doc.Status != PODOCStatusEnum.Approving)
                        throw new Exception($"单号：[{doc.DocNo}]状态不为提交，不能审核！");
                    if (doc.POLines == null || doc.POLines.Count == 0)
                        throw new Exception($"单号：[{doc.DocNo}]行为空");
                    if (doc.POLines[0].POShiplines == null || doc.POLines[0].POShiplines.Count == 0)
                        throw new Exception($"单号：[{doc.DocNo}]计划行为空");

                    //调用审核bp
                    POShipLine shipLine = doc.POLines[0].POShiplines[0];
                    SinglePoShipLineBP bp = new SinglePoShipLineBP();
                    bp.ActionType = ActivateTypeEnum.ApprovedAct;
                    bp.PoShipLineKey = shipLine.Key;
                    bp.PoShipLineSysVersion = shipLine.SysVersion;
                    bp.PoLineSysVersion = shipLine.POLine.SysVersion;
                    bp.PoSysVersion = doc.SysVersion;
                    POSysVersionDTO retdto = bp.Do();

					return doc;
                });
		}		
	}

	#endregion
	
	
}